/*
    外观模式是一种结构型设计模式， 能为程序库、 框架或其他复杂类提供一个简单的接口。
*/

#[derive(Debug)]
struct Oxygen {
    name: String,
}

#[derive(Debug)]
struct Iron {
    name: String,
}

struct Condition {
    iron: Iron,
    oxygen: Oxygen,
}

impl Oxygen {
    fn reaction(&mut self, name: String) {
        self.name = name
    }
}

impl Iron {
    fn reaction(&mut self, name: String) {
        self.name = name
    }
}

impl Condition {
    fn reaction(&self, condition: String) -> String {
        if condition.ends_with("s") {
            return format!("2 {:?} 化 3{:?} \n", self.oxygen.name, self.iron.name);
        };
        return format!("3 {:?} 化 4 {:?} \n", self.oxygen.name, self.iron.name);
    }
}

#[test]
fn main() {
    let condition = Condition {
        iron: Iron { name: "iron".to_string() },
        oxygen: Oxygen { name: "oxygen".to_string() },
    };
    println!("{}", condition.reaction(String::from("s")));
}